//
//  LKOpenShopStepOneViewController.m
//  Mideleague_Agent
//
//  Created by Zhiwang on 2020/6/3.
//  Copyright © 2020 Zhiwang. All rights reserved.
//

#import "LKOpenShopStepOneViewController.h"
#import "LKUFPictureRow.h"
#import "LKUFPictureRowCell.h"
#import "LKUFOpenShopHeaderRow.h"
#import "LKUFOpenShopHeaderRowCell.h"
#import "LKUFOpenShopBottomButtonRow.h"
#import "LKUFOpenShopBottomButtonRowCell.h"
#import "LKOpenShopStepTwoViewController.h"
#import "LKOpenShopIndustryModel.h"
#import "LKRateSettingViewController.h"
#import "LKOpenServiceViewController.h"
#import "LKWebViewController.h"
@interface LKOpenShopStepOneViewController ()<UFCustomPickerViewRowDelegate>{
    dispatch_group_t _group;
    dispatch_queue_t _queue;
    dispatch_semaphore_t semaphore;
}


@property(nonatomic,strong)UFFormView *formview;
@property(nonatomic,strong)NSMutableArray *dataArray;
@property(nonatomic,assign)NSInteger pictureTapSelectIndex;
@property(nonatomic,strong)NSMutableArray *industryArray;
@property(nonatomic,assign)NSInteger currentRow;
@property(nonatomic,assign)NSInteger currentSonRow;
@property(nonatomic,strong)UIImage *selcetedUploadImage;
@property(nonatomic,copy)NSString *exampleDescrip;
@property(nonatomic,copy)NSString *hadSetting;
@end

@implementation LKOpenShopStepOneViewController

- (void)viewDidLoad {
    [super viewDidLoad];
//    self.inforModel = [[LKMyShopOpenInforModel alloc] init];
    _group = dispatch_group_create();
    _queue = dispatch_queue_create("seriersQueue", DISPATCH_QUEUE_SERIAL);
      semaphore  = dispatch_semaphore_create(1);
    self.currentRow = 0;
    self.currentSonRow = 0;
    self.hadSetting = @"";
    self.navigationItem.title = @"商户开通";
    if (self.inforModel) {
        
    }else{
        
    }
//    if (self.listStatusModel) {
//        [self getDetailInformationAccoringUid:self.listStatusModel.Id];
//    }else{
//        self.inforModel = [[LKMyShopOpenInforModel alloc] init];
//        self.inforModel.uid = self.uid;
//        self.inforModel.referrer = [LKUserInforTool account].user_phone;
//        self.inforModel.merchant_name = self.merchant_name;
//        self.inforModel.merchant_jiancheng = self.merchant_name;
//        [self createFormView];
//    }
//    [self getDetailInformationAccoringUid:self.listStatusModel.Id];
    
    [self getDetailInformationAccoringUid:self.uid];
//    self.inforModel.merchant_name =
//    self.inforModel.referrer = self.listStatusModel.referrer;
//    self.inforModel.uid = self.listStatusModel.Id;
//    self.inforModel.merchant_name = self.listStatusModel.user_name;
    [self setNavgationRightBtn];
    self.dataArray = [[NSMutableArray alloc] initWithArray:@[@"ic_main_member_manage",@"ic_main_member_manage",@"ic_main_member_manage"]];
    [self getMyShopIndusty];
    // Do any additional setup after loading the view.
}
-(void)setNavgationRightBtn{
    WS(weakSelf)
    LKBaseButton *rightBtn = [LKBaseButton buttonWithFrame:CGRectMake(0, 0, 64, 24) type:UIButtonTypeCustom title:@"暂存" titleColor:COLOR_HEX(0x333333) layercorne:13 font:[UIFont fontWithName:@"PingFangSC-Regular" size: 16] backgroudColor:[UIColor clearColor] AndActionBlock:^(UIButton * _Nonnull btn) {
        weakSelf.inforModel.status = @"6";
        NSDictionary *param = [self.inforModel properties_aps];
        [[LKNetDataManager defaultManager] sendRequestMethod:HTTPMethodPOST serverUrl:ServerlUrl apiPath:MyShopOpenInformationEditUrl header:[LKUserInforTool account].token parameters:param progress:^(NSProgress * _Nullable progress) {
            
        } success:^(BOOL isSuccess, id  _Nullable responseObject) {
           [SVProgressHUD showInfoWithStatus:responseObject[@"msg"]];
            
        } failure:^(NSString * _Nullable errorMessage) {
            
        }];
    }];
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:rightBtn];
}
/// 创建表单的view
-(void)createFormView{
    WS(weakSelf)
    self.formview = [UFFormView makeFormView:^(UFFormViewMaker * _Nonnull make) {
        make
        .registerRow([LKUFOpenShopHeaderRow class], [LKUFOpenShopHeaderRowCell class])
        .registerRow([LKUFPictureRow class], [LKUFPictureRowCell class])
        .registerRow([LKUFOpenShopBottomButtonRow class], [LKUFOpenShopBottomButtonRowCell class])
        .addSection([UFSection makeSection:^(UFSectionMaker * _Nonnull make) {
            make
            .titleStyle([UFRowTitleStyle makeTitleStyle:^(UFRowTitleStyleMaker * _Nonnull make) {
               make
                .width(WIDTH/3 + 50)
                .font([UIFont fontWithName:@"PingFangSC-Regular" size:16])
                .color(labelBlackColor)
                .textAlignment(NSTextAlignmentLeft);
            }])
            .valueStyle([UFTextStyle makeTextStyle:^(UFRowTextStyleMaker * _Nonnull make) {
                make
                .textAlignment(NSTextAlignmentRight)
                .font([UIFont fontWithName:@"PingFangSC-Regular" size:16])
                .color(labelBlackColor);
            }])
            .addRowWithBlock(^__kindof UFRow * _Nonnull{
                LKUFOpenShopHeaderRow *row = [[LKUFOpenShopHeaderRow alloc] init];
                row.headerImage = [UIImage imageNamed:@"编组 9"];
                row.height = (WIDTH - 26)/7 + 20;
                return row;
            })
            .addRow([UFTextFieldRow makeTextFieldRow:^(UFTextFieldRowMaker * _Nonnull make) {
                make
                .editable(NO)
                .height(RowHeightDefault)
                .title(@"推荐人电话")
                .name(@"推荐人电话")
                .value([LKUserInforTool account].user_phone);
            }])
            .addRow([UFPickerViewRow makePickerViewRow:^(UFPickerViewRowMaker * _Nonnull make) {
                make
                .itemArray(@[@"个人",@"个体工商户",@"企业",@"小微商户"])
                .placeholder(@"请选择")
                .title(@"商户类型")
                .name(@"mcc_jc_id")
                .value([NSString backShopTypeAccordingType:self.inforModel.mcc_jc_id])
                .valueDidChanged(^(__kindof UFRow * _Nonnull row, NSString * _Nonnull value) {
                    weakSelf.inforModel.mcc_jc_id = [NSString backTypeAccordingShop:value];
                    if ([value isEqualToString:@"小微商户"]) {
                        [weakSelf.formview removeFromSuperview];
                        [weakSelf createXiaoVFormView];
                    }else{
                        [weakSelf.formview removeFromSuperview];
                        [weakSelf createFormView];
                    }
                    NSLog(@"选中的值%@",value);
                })
                .height(RowHeightDefault)
                .accessoryType(UFRowAccessoryDisclosureIndicator);
            }])
            .addRow([UFCustomPickerViewRow makeCustomPickerViewRow:^(UFCustomPickerViewRowMaker * _Nonnull make) {
                make
                .delegate(weakSelf)
                .valueDidSelected(^(__kindof UFCustomPickerViewRow * _Nonnull row, UITextField * _Nonnull textField) {
                    LKOpenShopIndustryModel *model = weakSelf.industryArray[weakSelf.currentRow];
                    
                    NSString *value = [NSString stringWithFormat:@"%@/%@",model.name,model.son[self.currentSonRow].name];
                    row.value = value;
                    self.inforModel.industry = model.Id;
                    self.inforModel.industry_two = model.son[self.currentSonRow].Id;
                    textField.text = value;
                    weakSelf.exampleDescrip = model.son[weakSelf.currentSonRow].desc;
                    weakSelf.inforModel.industry_name = value;
                    [weakSelf.formview removeFromSuperview];
                    [weakSelf createFormView];
                    weakSelf.currentRow = 0;
                    weakSelf.currentSonRow = 0;
                })
                .title(@"行业类型")
                .name(@"行业类型")
                .value(weakSelf.inforModel.industry_name)
                .accessoryType(UFRowAccessoryDisclosureIndicator);
            }])
            .addRow([UFTextViewRow makeTextViewRow:^(UFTextViewRowMaker * _Nonnull make) {
                make
                .editable(NO)
                .maxLength(0)
                .placeholder(@"请输入")
                .title(@"该类目适用企业举例")
                .name(@"msg")
                .value(weakSelf.exampleDescrip);
            }])
            .addRow([UFTextFieldRow makeTextFieldRow:^(UFTextFieldRowMaker * _Nonnull make) {
                make
                .height(RowHeightDefault)
                .title(@"客服电话")
                .name(@"kefu_phone")
                .valueDidChanged(^(__kindof UFRow * _Nonnull row, NSString * _Nonnull value) {
                    weakSelf.inforModel.kefu_phone = value;
                })
                .value(self.inforModel.kefu_phone);
            }])
            .addRow([UFTextFieldRow makeTextFieldRow:^(UFTextFieldRowMaker * _Nonnull make) {
                make
                .height(RowHeightDefault)
                .title(@"邮箱")
                .name(@"e_mail")
                .valueDidChanged(^(__kindof UFRow * _Nonnull row, NSString * _Nonnull value) {
                    self.inforModel.e_mail = value;
                })
                .value(self.inforModel.e_mail);
            }])
            .addRow([UFTextFieldRow makeTextFieldRow:^(UFTextFieldRowMaker * _Nonnull make) {
                make
                .editable(NO)
                .height(RowHeightDefault)
                .title(@"商户费率")
                .value(weakSelf.hadSetting)
                .rowDidSelected(^(__kindof UFRow * _Nonnull row) {
                    LKRateSettingViewController *vc = [[LKRateSettingViewController alloc] init];
                    vc.inforModel = weakSelf.inforModel;
                    vc.modelBlock = ^(LKMyShopOpenInforModel * _Nullable model) {
                        weakSelf.inforModel = model;
                        weakSelf.hadSetting = @"已设置";
                        row.value = weakSelf.hadSetting;
                        [weakSelf.formview removeFromSuperview];
                        if ([weakSelf.inforModel.mcc_jc_id isEqualToString:@"3"]) {
                            [weakSelf createXiaoVFormView];
                        }else{
                            [weakSelf createFormView];
                        }
                        
                    };
                    [weakSelf.navigationController pushViewController:vc animated:YES];
                })
                .accessoryType(UFRowAccessoryDisclosureIndicator);
            }])
            .addRowWithBlock(^__kindof UFRow * _Nonnull{
                LKUFPictureRow *pictureRow = [[LKUFPictureRow alloc] init];
                pictureRow.pictureNumbers = 4;
                pictureRow.headerTitle = @"店铺照片";
                pictureRow.titlesPlaceArray = @[@"+门头照",@"+收银台照",@"+内景照",@"+外景照"];
                if (self.inforModel.header_interior_img == nil) {

                }else{
                     pictureRow.picturesArray = [[NSMutableArray alloc] initWithArray:@[self.inforModel.header_interior_img,self.inforModel.cashier_img,self.inforModel.interior_img,self.inforModel.abroad_img]];
                }

                pictureRow.height = 250;
                pictureRow.uploadImageBlock = ^(NSInteger selectValue, UIImageView * _Nonnull selecteImageV) {
                    dispatch_group_notify(self->_group,dispatch_get_main_queue(), ^{
                        NSLog(@"完毕");
                        dispatch_semaphore_signal(self->semaphore);
                        weakSelf.pictureTapSelectIndex = 8;
                        [weakSelf showAlertChooseVc];
                    });

                };
                return pictureRow;
            })
            .addRowWithBlock(^__kindof UFRow * _Nonnull{
                LKUFOpenShopBottomButtonRow *buttonRow = [[LKUFOpenShopBottomButtonRow alloc] init];
                buttonRow.height = 300;
                buttonRow.isContainProtcoal = YES;
                buttonRow.actionBlock = ^{
                    if ([weakSelf.inforModel.mcc_jc_id isEqualToString:@"0"]) {
                        [SVProgressHUD showInfoWithStatus:@"请选择商户类型"];
                        return ;
                    }
                    if ([NSString isBlankString:weakSelf.inforModel.industry]) {
                        [SVProgressHUD showInfoWithStatus:@"请选择行业类型"];
                        return ;
                    }
                    if ([NSString isBlankString:weakSelf.inforModel.kefu_phone]) {
                        [SVProgressHUD showInfoWithStatus:@"请填写客服电话"];
                        return ;
                    }
                    if (weakSelf.inforModel.kefu_phone.length < 10 || weakSelf.inforModel.kefu_phone.length > 12) {
                        [SVProgressHUD showInfoWithStatus:@"请填写正确的客服电话"];
                        return ;
                    }
                    if ([NSString isBlankString:weakSelf.inforModel.e_mail]) {
                        [SVProgressHUD showInfoWithStatus:@"请填写电子邮箱"];
                        return ;
                    }
                    //商户费率
                    if ([NSString isBlankString:weakSelf.inforModel.wx_rate]) {
                        [SVProgressHUD showInfoWithStatus:@"请填写微信的商户费率"];
                        return ;
                    }
                    if ([NSString isBlankString:weakSelf.inforModel.zfb_rate]) {
                        [SVProgressHUD showInfoWithStatus:@"请填写支付宝的商户费率"];
                        return ;
                    }
                    if ([NSString isBlankString:weakSelf.inforModel.ysf2_rate]) {
                        [SVProgressHUD showInfoWithStatus:@"请填写云闪付的商户费率"];
                        return ;
                    }
                    if ([NSString isBlankString:weakSelf.inforModel.ysf_rate]) {
                        [SVProgressHUD showInfoWithStatus:@"请填写云闪付的商户费率"];
                        return ;
                    }
                    if ([NSString isBlankString:weakSelf.inforModel.ysf1_rate]) {
                        [SVProgressHUD showInfoWithStatus:@"请填写云闪付的商户费率"];
                        return ;
                    }
                    //
                    if ([NSString isBlankString:weakSelf.inforModel.header_interior_img]) {
                        [SVProgressHUD showInfoWithStatus:@"请选择商户门头照"];
                        return ;
                    }
                    if ([NSString isBlankString:weakSelf.inforModel.cashier_img]) {
                        [SVProgressHUD showInfoWithStatus:@"请选择收银台照"];
                        return ;
                    }
                    if ([NSString isBlankString:weakSelf.inforModel.interior_img]) {
                        [SVProgressHUD showInfoWithStatus:@"请选择内景照"];
                        return ;
                    }
                    if ([NSString isBlankString:weakSelf.inforModel.abroad_img]) {
                        [SVProgressHUD showInfoWithStatus:@"请选择外景照"];
                        return ;
                    }
                    weakSelf.inforModel.status = @"6";
                    NSDictionary *param = [self.inforModel properties_aps];
                    [[LKNetDataManager defaultManager] sendRequestMethod:HTTPMethodPOST serverUrl:ServerlUrl apiPath:MyShopOpenInformationEditUrl header:[LKUserInforTool account].token parameters:param progress:^(NSProgress * _Nullable progress) {
                        
                    } success:^(BOOL isSuccess, id  _Nullable responseObject) {
                       [SVProgressHUD showInfoWithStatus:responseObject[@"msg"]];
                        LKOpenShopStepTwoViewController *stepTwoVc = [[LKOpenShopStepTwoViewController alloc] init];
                        stepTwoVc.inforModel = weakSelf.inforModel;
                        [weakSelf.navigationController pushViewController:stepTwoVc animated:YES];
                    } failure:^(NSString * _Nullable errorMessage) {
                        
                    }];

                };
                buttonRow.agreeBtnBlock = ^{
                    
                };
                buttonRow.protcalABtnBlock = ^{
                    LKWebViewController *webVc = [[LKWebViewController alloc] init];
                    webVc.url = [NSString stringWithFormat:@"%@%@",ServerlUrl,@"index.php?s=api/app/services&app_name=4"];
                    [weakSelf.navigationController pushViewController:webVc animated:YES];
                    
                };
                buttonRow.protcalBBtnBlock = ^{
                    LKWebViewController *webVc = [[LKWebViewController alloc] init];
                    webVc.url = [NSString stringWithFormat:@"%@%@",ServerlUrl,@"index.php?s=api/app/settled&app_name=4"];
                    [weakSelf.navigationController pushViewController:webVc animated:YES];
                };
                return buttonRow;
            });
        }])
        .addToSuperView(self.view);
    }];
    [self.formview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(self.view);
        make.top.equalTo(self.view.mas_top).offset(NAVIGATION_BAR_HEIGHT);
        make.bottom.equalTo(self.view);
    }];
}
/// 创建小V的表单的view
-(void)createXiaoVFormView{
    WS(weakSelf)
    self.formview = [UFFormView makeFormView:^(UFFormViewMaker * _Nonnull make) {
        make
        .registerRow([LKUFOpenShopHeaderRow class], [LKUFOpenShopHeaderRowCell class])
        .registerRow([LKUFPictureRow class], [LKUFPictureRowCell class])
        .registerRow([LKUFOpenShopBottomButtonRow class], [LKUFOpenShopBottomButtonRowCell class])
        .addSection([UFSection makeSection:^(UFSectionMaker * _Nonnull make) {
            make
            .titleStyle([UFRowTitleStyle makeTitleStyle:^(UFRowTitleStyleMaker * _Nonnull make) {
               make
                .width(WIDTH/3 + 50)
                .font([UIFont fontWithName:@"PingFangSC-Regular" size:16])
                .color(labelBlackColor)
                .textAlignment(NSTextAlignmentLeft);
            }])
            .valueStyle([UFTextStyle makeTextStyle:^(UFRowTextStyleMaker * _Nonnull make) {
                make
                .textAlignment(NSTextAlignmentRight)
                .font([UIFont fontWithName:@"PingFangSC-Regular" size:16])
                .color(labelBlackColor);
            }])
            .addRowWithBlock(^__kindof UFRow * _Nonnull{
                LKUFOpenShopHeaderRow *row = [[LKUFOpenShopHeaderRow alloc] init];
                row.headerImage = [UIImage imageNamed:@"编组 9"];
                row.height = (WIDTH - 26)/7 + 20;
                return row;
            })
            .addRow([UFTextFieldRow makeTextFieldRow:^(UFTextFieldRowMaker * _Nonnull make) {
                make
                .editable(NO)
                .height(RowHeightDefault)
                .title(@"推荐人电话")
                .name(@"推荐人电话")
                .value([LKUserInforTool account].user_phone);
            }])
            .addRow([UFPickerViewRow makePickerViewRow:^(UFPickerViewRowMaker * _Nonnull make) {
                make
                .itemArray(@[@"个人",@"个体工商户",@"企业",@"小微商户"])
                .placeholder(@"请选择")
                .title(@"商户类型")
                .name(@"mcc_jc_id")
                .value([NSString backShopTypeAccordingType:self.inforModel.mcc_jc_id])
                .valueDidChanged(^(__kindof UFRow * _Nonnull row, NSString * _Nonnull value) {
                    weakSelf.inforModel.mcc_jc_id = [NSString backTypeAccordingShop:value];
                    if ([value isEqualToString:@"小微商户"]) {
                        [weakSelf.formview removeFromSuperview];
                        [weakSelf createXiaoVFormView];
                    }else{
                        [weakSelf.formview removeFromSuperview];
                        [weakSelf createFormView];
                    }
                    NSLog(@"选中的值%@",value);
                })
                .height(RowHeightDefault)
                .accessoryType(UFRowAccessoryDisclosureIndicator);
            }])
            .addRow([UFCustomPickerViewRow makeCustomPickerViewRow:^(UFCustomPickerViewRowMaker * _Nonnull make) {
                make
                .delegate(weakSelf)
                .valueDidSelected(^(__kindof UFCustomPickerViewRow * _Nonnull row, UITextField * _Nonnull textField) {
                    LKOpenShopIndustryModel *model = weakSelf.industryArray[weakSelf.currentRow];
                    NSString *value = [NSString stringWithFormat:@"%@/%@",model.name,model.son[weakSelf.currentSonRow].name];
                    row.value = value;
                    weakSelf.inforModel.industry = model.Id;
                    weakSelf.inforModel.industry_two = model.son[self.currentSonRow].Id;
                    textField.text = value;
                    weakSelf.exampleDescrip = model.son[weakSelf.currentSonRow].desc;
                    weakSelf.inforModel.industry_name = value;
                    [weakSelf.formview removeFromSuperview];
                    [weakSelf createXiaoVFormView];
                    weakSelf.currentRow = 0;
                    weakSelf.currentSonRow = 0;
                })
                .title(@"行业类型")
                .name(@"行业类型")
                .value(weakSelf.inforModel.industry_name)
                .accessoryType(UFRowAccessoryDisclosureIndicator);
            }])
            .addRow([UFTextViewRow makeTextViewRow:^(UFTextViewRowMaker * _Nonnull make) {
                make
                .editable(NO)
                .maxLength(0)
                .placeholder(@"请输入")
                .title(@"该类目适用企业举例")
                .name(@"msg")
                .value(weakSelf.exampleDescrip);
            }])
            .addRow([UFPickerViewRow makePickerViewRow:^(UFPickerViewRowMaker * _Nonnull make) {
                make
         .itemArray(@[@"餐饮",@"线下零售",@"居民生活服务",@"休闲娱乐",@"交通出行",@"其他"])
                .placeholder(@"请选择")
                .title(@"售卖商品/提供服务")
                .name(@"售卖商品/提供服务")
                .value(weakSelf.inforModel.service_description)
                .height(RowHeightDefault)
                .valueDidChanged(^(__kindof UFRow * _Nonnull row, NSString * _Nonnull value) {
                    weakSelf.inforModel.service_description = value;
                })
                .accessoryType(UFRowAccessoryDisclosureIndicator);
            }])
            .addRow([UFTextFieldRow makeTextFieldRow:^(UFTextFieldRowMaker * _Nonnull make) {
                make
                .height(RowHeightDefault)
                .title(@"客服电话")
                .name(@"kefu_phone")
                .valueDidChanged(^(__kindof UFRow * _Nonnull row, NSString * _Nonnull value) {
                    weakSelf.inforModel.kefu_phone = value;
                })
                .value(self.inforModel.kefu_phone);
            }])
            .addRow([UFTextFieldRow makeTextFieldRow:^(UFTextFieldRowMaker * _Nonnull make) {
                make
                .height(RowHeightDefault)
                .title(@"邮箱")
                .name(@"e_mail")
                .valueDidChanged(^(__kindof UFRow * _Nonnull row, NSString * _Nonnull value) {
                    self.inforModel.e_mail = value;
                })
                .value(self.inforModel.e_mail);
            }])
            .addRow([UFTextFieldRow makeTextFieldRow:^(UFTextFieldRowMaker * _Nonnull make) {
                make
                .editable(NO)
                .height(RowHeightDefault)
                .title(@"商户费率")
                .value(weakSelf.hadSetting)
                .rowDidSelected(^(__kindof UFRow * _Nonnull row) {
                    LKRateSettingViewController *vc = [[LKRateSettingViewController alloc] init];
                    vc.inforModel = weakSelf.inforModel;
                    vc.modelBlock = ^(LKMyShopOpenInforModel * _Nullable model) {
                        weakSelf.inforModel = model;
                        weakSelf.hadSetting = @"已设置";
                        row.value = weakSelf.hadSetting;
                        [weakSelf.formview removeFromSuperview];
                          if ([weakSelf.inforModel.mcc_jc_id isEqualToString:@"3"]) {
                            [weakSelf.formview removeFromSuperview];
                            [weakSelf createXiaoVFormView];
                        }else{
                            [weakSelf.formview removeFromSuperview];
                            [weakSelf createFormView];
                        }
                    };
                    [weakSelf.navigationController pushViewController:vc animated:YES];
                })
                .accessoryType(UFRowAccessoryDisclosureIndicator);
            }])
            .addRowWithBlock(^__kindof UFRow * _Nonnull{
                LKUFPictureRow *pictureRow = [[LKUFPictureRow alloc] init];
                pictureRow.pictureNumbers = 4;
                pictureRow.headerTitle = @"店铺照片";
                pictureRow.titlesPlaceArray = @[@"+门头照",@"+收银台照",@"+内景照",@"+外景照"];
                pictureRow.picturesArray = [[NSMutableArray alloc] initWithArray:@[weakSelf.inforModel.header_interior_img,weakSelf.inforModel.cashier_img,weakSelf.inforModel.interior_img,weakSelf.inforModel.abroad_img]];
                pictureRow.height = 250;
                pictureRow.uploadImageBlock = ^(NSInteger selectValue, UIImageView * _Nonnull selecteImageV) {
                    dispatch_group_notify(self->_group, dispatch_get_main_queue(), ^{
                        dispatch_semaphore_signal(self->semaphore);
                        weakSelf.pictureTapSelectIndex = 9;
                        [weakSelf showAlertChooseVc];
//                        dispatch_semaphore_wait(self->semaphore, DISPATCH_TIME_FOREVER);
                    });

                };
                return pictureRow;
            })
            .addRowWithBlock(^__kindof UFRow * _Nonnull{
                LKUFOpenShopBottomButtonRow *buttonRow = [[LKUFOpenShopBottomButtonRow alloc] init];
                buttonRow.height = 300;
                buttonRow.isContainProtcoal = YES;
                buttonRow.actionBlock = ^{
                    if ([weakSelf.inforModel.mcc_jc_id isEqualToString:@"0"]) {
                        [SVProgressHUD showInfoWithStatus:@"请选择商户类型"];
                        return ;
                    }
                    if ([NSString isBlankString:weakSelf.inforModel.industry]) {
                        [SVProgressHUD showInfoWithStatus:@"请选择行业类型"];
                        return ;
                    }
                    if ([NSString isBlankString:weakSelf.inforModel.kefu_phone]) {
                        [SVProgressHUD showInfoWithStatus:@"请填写客服电话"];
                        return ;
                    }
                    if (weakSelf.inforModel.kefu_phone.length < 10 || weakSelf.inforModel.kefu_phone.length > 12) {
                        [SVProgressHUD showInfoWithStatus:@"请填写正确的客服电话"];
                        return ;
                    }
                    if ([NSString isBlankString:weakSelf.inforModel.e_mail]) {
                        [SVProgressHUD showInfoWithStatus:@"请选择电子邮箱"];
                        return ;
                    }
                    //商户费率
                    if ([NSString isBlankString:weakSelf.inforModel.wx_rate]) {
                        [SVProgressHUD showInfoWithStatus:@"请填写微信的商户费率"];
                        return ;
                    }
                    if ([NSString isBlankString:weakSelf.inforModel.zfb_rate]) {
                        [SVProgressHUD showInfoWithStatus:@"请填写支付宝的商户费率"];
                        return ;
                    }
                    if ([NSString isBlankString:weakSelf.inforModel.ysf2_rate]) {
                        [SVProgressHUD showInfoWithStatus:@"请填写云闪付的商户费率"];
                        return ;
                    }
                    if ([NSString isBlankString:weakSelf.inforModel.ysf_rate]) {
                        [SVProgressHUD showInfoWithStatus:@"请填写云闪付的商户费率"];
                        return ;
                    }
                    if ([NSString isBlankString:weakSelf.inforModel.service_description]) {
                        [SVProgressHUD showInfoWithStatus:@"请选择服务描述"];
                        return;
                    }
                    if ([NSString isBlankString:weakSelf.inforModel.ysf1_rate]) {
                        [SVProgressHUD showInfoWithStatus:@"请填写云闪付的商户费率"];
                        return ;
                    }
                    //
                    if ([NSString isBlankString:weakSelf.inforModel.header_interior_img]) {
                        [SVProgressHUD showInfoWithStatus:@"请选择商户门头照"];
                        return ;
                    }
                    if ([NSString isBlankString:weakSelf.inforModel.cashier_img]) {
                        [SVProgressHUD showInfoWithStatus:@"请选择收银台照"];
                        return ;
                    }
                    if ([NSString isBlankString:weakSelf.inforModel.interior_img]) {
                        [SVProgressHUD showInfoWithStatus:@"请选择内景照"];
                        return ;
                    }
                    if ([NSString isBlankString:weakSelf.inforModel.abroad_img]) {
                        [SVProgressHUD showInfoWithStatus:@"请选择外景照"];
                        return ;
                    }
                    weakSelf.inforModel.status = @"6";
                    NSDictionary *param = [self.inforModel properties_aps];
                    [[LKNetDataManager defaultManager] sendRequestMethod:HTTPMethodPOST serverUrl:ServerlUrl apiPath:MyShopOpenInformationEditUrl header:[LKUserInforTool account].token parameters:param progress:^(NSProgress * _Nullable progress) {
                        
                    } success:^(BOOL isSuccess, id  _Nullable responseObject) {
                       [SVProgressHUD showInfoWithStatus:responseObject[@"msg"]];
                        LKOpenShopStepTwoViewController *stepTwoVc = [[LKOpenShopStepTwoViewController alloc] init];
                        stepTwoVc.inforModel = weakSelf.inforModel;
                        [weakSelf.navigationController pushViewController:stepTwoVc animated:YES];
                    } failure:^(NSString * _Nullable errorMessage) {
                        
                    }];
                };
                buttonRow.agreeBtnBlock = ^{
                    
                };
                buttonRow.protcalABtnBlock = ^{
                    
                };
                buttonRow.protcalBBtnBlock = ^{
                    
                };
                return buttonRow;
            });
        }])
        .addToSuperView(self.view);
    }];
    [self.formview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(self.view);
        make.top.equalTo(self.view.mas_top).offset(NAVIGATION_BAR_HEIGHT);
        make.bottom.equalTo(self.view);
    }];
}

-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<UIImagePickerControllerInfoKey,id> *)info{
    NSString *type = [info objectForKey:UIImagePickerControllerMediaType];
    if ([type isEqualToString:@"public.image"]) {

        UIImage *photo = [info objectForKey:UIImagePickerControllerOriginalImage];
        LKUFPictureRow *row = [self.formview findRowInRange:UFMakeRange(0, self.pictureTapSelectIndex)];
        NSLog(@"选中的%ld",row.selectImageV.tag);
        row.selectImageV.image = photo;
        row.selectImageV.superview.userInteractionEnabled = NO;
        self.selcetedUploadImage = row.selectImageV.image;
        dispatch_group_enter(_group);
        dispatch_group_async(_group, dispatch_get_main_queue(), ^{
//            dispatch_semaphore_signal(self->semaphore);
            [SVProgressHUD showWithStatus:@"图片上传中..."];
            [[LKNetDataManager defaultManager] sendPOSTRequestWithserverUrl:ServerlUrl apiPath:ImageUploadUrl parameters:nil imageArray:@[self.selcetedUploadImage] targetWidth:100 progress:^(NSProgress * _Nullable progress) {
                
            } success:^(BOOL isSuccess, id  _Nullable responseObject) {
                    row.selectImageV.superview.userInteractionEnabled = YES;
                dispatch_group_leave(self->_group);
                dispatch_semaphore_wait(self->semaphore, DISPATCH_TIME_FOREVER);
                NSLog(@"赋值完毕");
                [SVProgressHUD dismiss];
                if ([responseObject[@"code"] isEqualToString:@"success"]) {
                    if ([NSString isBlankString:responseObject[@"data"]]) {
                        [SVProgressHUD showInfoWithStatus:@"图片未上传成功，请重新选择"];
                        return ;
                    }
                    switch (row.selectImageV.tag - 1000) {
                        case 0:
                        {
                            self.inforModel.header_interior_img = responseObject[@"data"];
                        }
                            break;
                        case 1:
                        {
                            self.inforModel.cashier_img = responseObject[@"data"];
                        }
                            break;
                        case 2:
                        {
                            self.inforModel.interior_img = responseObject[@"data"];
                        }
                            break;
                        case 3:
                        {
                            self.inforModel.abroad_img = responseObject[@"data"];
                        }
                            break;
                        default:
                            break;
                    }
                }else{
                    row.selectImageV.superview.userInteractionEnabled = YES;
                    dispatch_group_leave(self->_group);
                    [SVProgressHUD showInfoWithStatus:responseObject[@"msg"]];
                }

            } failure:^(NSString * _Nullable error) {
                
            }];
        });

    }
    [picker dismissViewControllerAnimated:YES completion:nil];
}

-(void)imagePickerController:(TZImagePickerController *)picker didFinishPickingPhotos:(NSArray<UIImage *> *)photos sourceAssets:(NSArray *)assets isSelectOriginalPhoto:(BOOL)isSelectOriginalPhoto infos:(NSArray<NSDictionary *> *)infos{
    LKUFPictureRow *row = [self.formview findRowInRange:UFMakeRange(0, self.pictureTapSelectIndex)];
        row.selectImageV.superview.userInteractionEnabled = NO;
    NSLog(@"选中的%ld",row.selectImageV.tag);
    row.selectImageV.image = photos[0];
    self.selcetedUploadImage = row.selectImageV.image;
    dispatch_group_enter(_group);
    dispatch_group_async(_group, dispatch_get_main_queue(), ^{
        [SVProgressHUD showWithStatus:@"图片上传中..."];
        [[LKNetDataManager defaultManager] sendPOSTRequestWithserverUrl:ServerlUrl apiPath:ImageUploadUrl parameters:nil imageArray:@[self.selcetedUploadImage] targetWidth:100 progress:^(NSProgress * _Nullable progress) {
            
        } success:^(BOOL isSuccess, id  _Nullable responseObject) {
NSLog(@"该死的图片地址选中了%ld=%@",row.selectImageV.tag,responseObject[@"data"]);
            dispatch_group_leave(self->_group);
            dispatch_semaphore_wait(self->semaphore, DISPATCH_TIME_FOREVER);
            if ([responseObject[@"code"] isEqualToString:@"success"]) {
                if ([NSString isBlankString:responseObject[@"data"]]) {
                    
                    [SVProgressHUD showInfoWithStatus:@"图片未上传成功，请重新选择"];
                    return ;
                }
                switch (row.selectImageV.tag - 1000) {
                    case 0:
                    {
                        self.inforModel.header_interior_img = responseObject[@"data"];
                    }
                        break;
                    case 1:
                    {
                        self.inforModel.cashier_img = responseObject[@"data"];
                    }
                        break;
                    case 2:
                    {
                        self.inforModel.interior_img = responseObject[@"data"];
                    }
                        break;
                    case 3:
                    {
                        self.inforModel.abroad_img = responseObject[@"data"];
                    }
                        break;
                    default:
                        break;
                }

                [SVProgressHUD dismiss];
                row.selectImageV.superview.userInteractionEnabled = YES;
            }else{
                dispatch_group_leave(self->_group);
                [SVProgressHUD showInfoWithStatus:responseObject[@"msg"]];
                 row.selectImageV.superview.userInteractionEnabled = YES;
            }

        } failure:^(NSString * _Nullable error) {
            
        }];

    });

}



-(NSMutableArray *)industryArray{
    if (_industryArray == nil) {
        _industryArray = [[NSMutableArray alloc] init];
    }
    return _industryArray;
}
/// 获取我的行业
-(void)getMyShopIndusty{
    NSDictionary *param = @{@"token":[LKUserInforTool account].token};
    [[LKNetDataManager defaultManager] sendRequestMethod:HTTPMethodPOST serverUrl:ServerlUrl apiPath:MyShopOpenIndustryUrl header:[LKUserInforTool account].token parameters:param progress:^(NSProgress * _Nullable progress) {
        
    } success:^(BOOL isSuccess, id  _Nullable responseObject) {
        NSArray *dataArray = responseObject[@"data"];
        for (NSDictionary *dic in dataArray) {
            LKOpenShopIndustryModel *indusModel = [LKOpenShopIndustryModel modelWithDictionary:dic];
            if ([indusModel.Id isEqualToString:self.inforModel.industry]) {
                for (LKOpenShopIndustryModel *sonModel in indusModel.son) {
                if ([sonModel.Id isEqualToString:self.inforModel.industry_two]) {
                    self.exampleDescrip = sonModel.desc;
                }
            }
           }
            [self.industryArray addObject:indusModel];
        }
        if ([self.inforModel.mcc_jc_id isEqualToString:@"3"]) {
            [self.formview removeFromSuperview];
            [self createXiaoVFormView];
        }else{
            [self.formview removeFromSuperview];
            [self createFormView];
        }
    } failure:^(NSString * _Nullable errorMessage) {
        
    }];
}
#pragma mark -customPickerView的代理
- (NSInteger)numberOfComponentsInPickerViewRow:(nonnull UFCustomPickerViewRow *)pickerViewRow {
    return 2;
}
//
- (NSInteger)pickerViewRow:(nonnull UFCustomPickerViewRow *)pickerViewRow numberOfRowsInComponent:(NSInteger)component {
    if (component == 0) {
        return [self.industryArray count];
    }
    if (component == 1) {
        LKOpenShopIndustryModel *model = self.industryArray[self.currentRow];
        return model.son.count;
    }
    return 1;
}
//
- (nonnull NSString *)pickerViewRow:(nonnull UFCustomPickerViewRow *)pickerViewRow titleForRow:(NSInteger)row forComponent:(NSInteger)component {

    if (component == 0) {
        LKOpenShopIndustryModel *model = self.industryArray[row];
        return model.name;
    }
    if (component == 1) {
        LKOpenShopIndustryModel *currentModel = self.industryArray[self.currentRow];
        return currentModel.son[row].name;
    }
    return @"";

}
//
- (void)pickerViewRow:(nonnull UFCustomPickerViewRow *)pickerViewRow didSelectRow:(NSInteger)row inComponent:(NSInteger)component {
    if (component == 0) {
        self.currentRow = row;
    }
    if (component == 1) {
        self.currentSonRow = row;
    }
}
/// 根据uid返回详细信息
/// @param uid 商户ID
-(void)getDetailInformationAccoringUid:(NSString *)uid{
    if (uid) {
        [SVProgressHUD show];
        NSDictionary *param = @{@"uid":uid};
        [[LKNetDataManager defaultManager] sendRequestMethod:HTTPMethodPOST serverUrl:ServerlUrl apiPath:MyShopOpenDetailInforUrl header:[LKUserInforTool account].token parameters:param progress:^(NSProgress * _Nullable progress) {
            
        } success:^(BOOL isSuccess, id  _Nullable responseObject) {
            [SVProgressHUD dismiss];
            if ([responseObject[@"code"] isEqualToString:@"success"]) {
                self.inforModel = [LKMyShopOpenInforModel modelWithDictionary:responseObject[@"data"]];
                self.inforModel.status = @"6";
                if (![NSString isBlankString:self.inforModel.wx_rate]) {
                    self.hadSetting = @"已设置";
                }
                if ([self.inforModel.mcc_jc_id isEqualToString:@"3"]) {
                    [self createXiaoVFormView];
                }else{
                    [self createFormView];
                }
            }else{
                [SVProgressHUD showInfoWithStatus:responseObject[@"msg"]];
            }
        } failure:^(NSString * _Nullable errorMessage) {
            
        }];
    }
    
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
